package com.ruoyi.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.order.domain.SrvConttype;
import com.ruoyi.order.service.ISrvConttypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 内容分类Controller
 * 
 * @author ruoyi
 * @date 2021-01-29
 */
@RestController
@RequestMapping("/conttype")
public class SrvConttypeController extends BaseController
{
    @Autowired
    private ISrvConttypeService srvConttypeService;

    /**
     * 查询内容分类列表
     */
    @PreAuthorize(hasPermi = "system:conttype:list")
    @GetMapping("/list")
    public TableDataInfo list(SrvConttype srvConttype)
    {
        startPage();
        List<SrvConttype> list = srvConttypeService.selectSrvConttypeList(srvConttype);
        return getDataTable(list);
    }

    /**
     * 导出内容分类列表
     */
    @PreAuthorize(hasPermi = "system:conttype:export")
    @Log(title = "内容分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrvConttype srvConttype) throws IOException
    {
        List<SrvConttype> list = srvConttypeService.selectSrvConttypeList(srvConttype);
        ExcelUtil<SrvConttype> util = new ExcelUtil<SrvConttype>(SrvConttype.class);
        util.exportExcel(response, list, "conttype");
    }

    /**
     * 获取内容分类详细信息
     */
    @PreAuthorize(hasPermi = "system:conttype:query")
    @GetMapping(value = "/{srvCtcode}")
    public AjaxResult getInfo(@PathVariable("srvCtcode") String srvCtcode)
    {
        return AjaxResult.success(srvConttypeService.selectSrvConttypeById(srvCtcode));
    }

    /**
     * 新增内容分类
     */
    @PreAuthorize(hasPermi = "system:conttype:add")
    @Log(title = "内容分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrvConttype srvConttype)
    {
        return toAjax(srvConttypeService.insertSrvConttype(srvConttype));
    }

    /**
     * 修改内容分类
     */
    @PreAuthorize(hasPermi = "system:conttype:edit")
    @Log(title = "内容分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SrvConttype srvConttype)
    {
        return toAjax(srvConttypeService.updateSrvConttype(srvConttype));
    }

    /**
     * 删除内容分类
     */
    @PreAuthorize(hasPermi = "system:conttype:remove")
    @Log(title = "内容分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{srvCtcodes}")
    public AjaxResult remove(@PathVariable String[] srvCtcodes)
    {
        return toAjax(srvConttypeService.deleteSrvConttypeByIds(srvCtcodes));
    }
}
